﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using cogency;
using cogency.languages;
using cogency.languages.java;
using cogency.languages.csharp;
using cogency.representation;

namespace cogencyc
{
    class Program
    {
        static void Main(string[] args)
        {
            RNamespace test = new RNamespace("rpc");

            test.Declarations.Add(
                RDeclare.EnumDecl("SampleEnum", "Comment for SampleEnum", RDeclarationScope.Public,
                    RDeclare.EnumValue("Foo", "Comment on SampleEnum.Foo", "1"),
                    RDeclare.EnumValue("Bar", "Comment on SampleEnum.Bar", "2"),
                    RDeclare.EnumValue("Sep", "Comment on SampleEnum.Sep", "3")
                    ));

            test.Declarations.Add(
                RDeclare.ClassDecl("SampleClass", "Comment for SampleClass", RDeclarationScope.Public,
                    RDeclare.BuiltinInt32("I32Val", "Comment for i32Val", RDeclarationScope.Public),
                    RDeclare.BuiltinString("StrVal", "Comment for strVal", RDeclarationScope.Public),
                    RDeclare.EnumRef("SampleEnum", "SVal", "Comment for SampleEnum-typed SVal", RDeclarationScope.Public)
                    )
                );

            test.Declarations.Add(
                RDeclare.InterfaceDecl("MyFirstServer", "Comment for MyFirstServer", RDeclarationScope.Public,
                    RDeclare.Method("Add", "Comment for Add", RDeclarationScope.Ignored, 
                        RDeclare.BuiltinInt32(null, "Comment for return int value"),
                        RDeclare.BuiltinInt32("a", "Comment for parameter a"),
                        RDeclare.BuiltinInt32("b", "Comment for parameter b")),
                    RDeclare.Method("GetSampleInstance", "Comment for GetSampleInstance", RDeclarationScope.Ignored,
                    RDeclare.ClassRef("SampleClass", null, "Comment for return SampleClass value")),
                    RDeclare.Method("SetSampleInstance", "Comment for SetSampleInstance", RDeclarationScope.Ignored,
                        null,
                        RDeclare.ClassRef("SampleClass", "input", "Comment for SampleClass parameter"))
                    )
                );

            string license = @"Copyright (c) 2013, Gerson Kurz
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer. Redistributions in binary form must
reproduce the above copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided with the distribution.

Neither the name regdiff nor the names of its contributors may be used to endorse
or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.";


            List<CodeWriterContext> contexts = new List<CodeWriterContext>();
            contexts.Add(new CodeWriterContext(
                    @"C:\Projects\2014\cogency\Examples\Example01CSharpClient", 
                    "Example01CSharpClient",
                    CodeTargetType.XmlRpcClient,
                    test,
                    license));
            contexts.Add(new CodeWriterContext(
                    @"C:\Projects\2014\cogency\Examples\Example01CSharpServer",
                    "Example01CSharpServer",
                    CodeTargetType.XmlRpcStatelessServer,
                    test,
                    license));

            foreach (CodeWriterContext context in contexts)
            {
                new CSharpWriter(context).Process();
            }

            contexts.Clear();
            contexts.Add(new CodeWriterContext(
                                @"C:\Projects\2014\cogency\Examples\Example01JavaClient",
                                "Example01JavaClient",
                                CodeTargetType.XmlRpcClient,
                                test,
                                license));

            foreach (CodeWriterContext context in contexts)
            {
                new JavaWriter(context).Process();
            }
        }
    }
}
